/**
 * 
 */
package edu.isistan.genetic.operators;

import java.util.Vector;

import edu.isistan.metamodel.DataType;

/**
 * @author marcos.trotti
 *
 */
public class UpCasting implements Operator {
	protected String sourceType;
	protected String targetType;

	
	/**
	 * @param sourceType
	 * @param targetType
	 */
	public UpCasting(String sourceType, String targetType) {
		super();
		this.sourceType = sourceType;
		this.targetType = targetType;
	}
	
	
	public boolean isEncapsulationCompatible(){
		return false;
	}
	/* (non-Javadoc)
	 * @see Operators.Operator#isCompatible(edu.isistan.metamodel.DataType)
	 */
	
	public boolean isCompatible(DataType aDataType) {
		return aDataType.getType().endsWith(this.sourceType);
	}

	/* (non-Javadoc)
	 * @see Operators.Operator#mutate(edu.isistan.metamodel.DataType)
	 */
	
	public Vector<DataType> mutate(Vector<DataType> aDataTypes) {
		Vector<DataType> aResultSet = new Vector<DataType>();
		for (DataType aDataType : aDataTypes){
			if (this.isCompatible(aDataType)){
				aDataType.setType(this.targetType);
				aResultSet.add(aDataType);
			}
		}
		return aResultSet;
	}

	@Override
	public String toString() {
		return "UpCasting from " + sourceType + " to "+ targetType ;
	}

	
}
